<template>
	<view class="home">
		<view class="header">
			<view class="header-search">
				<uni-easyinput @confirm="handleSearch" suffixIcon="search" v-model="searchVal" placeholder="输入搜索关键词"
					@iconClick="handleSearch" :inputBorder="false" :trim="true"></uni-easyinput>
			</view>
		</view>
		<view class="header-circle"></view>
		<view class="home-swbox">
			<swiper class="home-swiper" circular indicator-dots="true" indicator-color="#fff" indicator-active-color="#00922a"
				:autoplay="true">
				<swiper-item v-for="item in 3">
					<image src="http://baihang.com.cn/Upload/image/2019093009XZJBSL.jpg" mode="aspectFill"></image>
				</swiper-item>
			</swiper>
		</view>
		<view class="home-news">
			<view class="home-newbox">
				<text class="home-newtit">新闻中心：</text>
				<swiper class="news-sw" :circular="true" :autoplay="true" :vertical="true">
					<swiper-item v-for="item in 3">
						<navigator url="" hover-class="none"><text>吉尔吉药业“携手共进，赢在龙年”新年赢在龙年”新年赢在龙年”新年</text></navigator>
					</swiper-item>
				</swiper>
				<uni-icons class="newicon" type="right" color="#a0a0a0"></uni-icons>
			</view>
		</view>
		<view class="fast-nav">
			<navigator url="/pages/my/single" class="fast-nav-item" hover-class="none">
				<image src="../../static/icon01.png" mode="aspectFit"></image>
				<text>企业简介</text>
			</navigator>
			<navigator url="/pages/search/search?val=中药配方颗粒" class="fast-nav-item" hover-class="none">
				<image src="../../static/icon02.png" mode="aspectFit"></image>
				<text>中药配方颗粒</text>
			</navigator>
			<navigator url="/pages/search/search?val=中药饮片" class="fast-nav-item" hover-class="none">
				<image src="../../static/icon03.png" mode="aspectFit"></image>
				<text>中药饮片</text>
			</navigator>
			<navigator url="/pages/search/search?val=食品" class="fast-nav-item" hover-class="none">
				<image src="../../static/icon04.png" mode="aspectFit"></image>
				<text>食品</text>
			</navigator>
			<navigator url="/pages/search/search?val=活动专区" class="fast-nav-item" hover-class="none">
				<image src="../../static/icon05.png" mode="aspectFit"></image>
				<text>活动专区</text>
			</navigator>
			<navigator url="/pages/search/search?val=每周一方" class="fast-nav-item" hover-class="none">
				<image src="../../static/icon06.png" mode="aspectFit"></image>
				<text>每周一方</text>
			</navigator>
			<navigator url="/pages/my/qual" class="fast-nav-item" hover-class="none">
				<image src="../../static/icon07.png" mode="aspectFit"></image>
				<text>资质审核</text>
			</navigator>
			<navigator url="/pages/my/my" open-type="switchTab" class="fast-nav-item" hover-class="none">
				<image src="../../static/icon08.png" mode="aspectFit"></image>
				<text>会员中心</text>
			</navigator>
		</view>
		<!-- 精选推荐 -->
		<view class="jxtj">
			<view class="jxtj-box">
				<view class="jxtj-top">
					<view class="jxtj-tit">
						<image src="../../static/icon09.png" mode="aspectFit"></image>
						<text>精选推荐</text>
					</view>
					<navigator url="/pages/search/search?val=精选推荐" class="jxtj-more" hover-class="none">更多<uni-icons type="right" color="#fff"></uni-icons>
					</navigator>
				</view>
				<view class="jxtj-sws">
					<uni-swiper-dot class="jxbox" :current="current2" :info="info2" mode="dot"
						:dots-styles="{backgroundColor:'#fff',selectedBackgroundColor:'#ca9c52',bottom:10,border:'1px solid #fff',selectedBorder:'1px solid #ca9c52'}"
						:pd="true">
						<swiper class="jxsw" @change="change2" autoplay="true" circular="true">
							<swiper-item v-for="(item, index) in info2" :key="index">
								<view class="jxswbox">
									<navigator class="jxitem" v-for="(sitem,sindex) in item" :key="sindex" hover-class="none"
										url="/pages/proinfo/proinfo">
										<view class="jximgbox">
											<view class="jxtip">厂家直销</view>
											<image class="jximg" :src="sitem.img" mode="aspectFit"></image>
										</view>
										<view class="jxinfo">
											<view class="jxtitle">{{sitem.title}}</view>
											<view class="jxspcc">包装规格：{{sitem.spcc}}</view>
											<view class="jxprice" v-if="isLogin">￥{{sitem.price}}</view>
											<view class="jxlogin" v-else>￥认证后可见</view>
										</view>
									</navigator>
								</view>
							</swiper-item>
						</swiper>
					</uni-swiper-dot>
				</view>
			</view>
		</view>
		<view class="home-list">
			<navigator url="/pages/proinfo/proinfo" class="home-pitem" v-for="(item,index) in prolist" :key="index"
				hover-class="none">
				<view class="home-pitem-l">
					<view class="jximgbox">
						<view class="jxstips">中药配方颗粒</view>
						<image class="jximg" :src="item.img" mode="aspectFit"></image>
					</view>
				</view>
				<view class="jxinfo">
					<view class="jxinfo-t">
						<view class="jxtitle">{{item.title}}</view>
						<view class="jxspcc">包装规格：{{item.spcc}}</view>
						<view class="jxprice" v-if="isLogin">￥{{item.price}}</view>
						<view class="jxlogin" v-else>￥认证后可见</view>
						<view class="jxtip">厂家直销</view>
					</view>
					<view class="jxinfo-b">
						<view class="jxinfo-b-l">详细<uni-icons type="right" size="12" color="#999999"></uni-icons>
						</view>
						<view class="jxinfo-b-r">→</view>
					</view>
				</view>
			</navigator>
		</view>
	</view>
</template>

<script setup>
	import {
		ref
	} from "vue";
	import {
		onLoad
	} from "@dcloudio/uni-app"
	const searchVal = ref("")
	const handleSearch = () => {
		console.log(searchVal.value)
	}

	onLoad(() => {
		//是否登录
		const isLogin = ref(false)

		// 精选推荐 需要转为二维数组
		const info = [{
			id: 1,
			title: "矮地茶配方颗粒",
			spcc: "每袋装0.83g",
			img: 'http://baihang.com.cn/Upload/image/2021122911RPF36Q.jpg',
			price: 19.00
		}, {
			id: 2,
			title: "矮地茶配方颗粒",
			spcc: "每袋装0.83g",
			img: 'http://baihang.com.cn/Upload/image/2022010404SU74QN.jpg',
			price: 11.00
		}, {
			id: 3,
			title: "矮地茶配方颗粒",
			spcc: "每袋装0.83g",
			img: 'http://baihang.com.cn/Upload/image/2021090904LMFFG9.jpg',
			price: 16.00
		}, {
			id: 4,
			title: "矮地茶配方颗粒",
			spcc: "每袋装0.83g",
			img: 'http://baihang.com.cn/Upload/image/2021090904LMFFG9.jpg',
			price: 18.00
		}, {
			id: 5,
			title: "矮地茶配方颗粒",
			spcc: "每袋装0.83g",
			img: 'http://baihang.com.cn/Upload/image/2021090904LMFFG9.jpg',
			price: 18.00
		}];
		for (let i = 0; i < info.length; i += 2) {
			info2.value.push(info.slice(i, i + 2));
		}
	})
	const info2 = ref([]);
	const current2 = ref(0);

	const change2 = (e) => {
		current2.value = e.detail.current;
	}
	//最后列表
	const prolist = ref([{
		id: 1,
		title: "矮地茶配方颗粒",
		spcc: "每袋装0.83g",
		img: 'http://baihang.com.cn/Upload/image/2021122911RPF36Q.jpg',
		price: 19.00
	}, {
		id: 2,
		title: "矮地茶配方颗粒",
		spcc: "每袋装0.83g",
		img: 'http://baihang.com.cn/Upload/image/2022010404SU74QN.jpg',
		price: 11.00
	}, {
		id: 3,
		title: "矮地茶配方颗粒",
		spcc: "每袋装0.83g",
		img: 'http://baihang.com.cn/Upload/image/2021090904LMFFG9.jpg',
		price: 16.00
	}, {
		id: 4,
		title: "矮地茶配方颗粒",
		spcc: "每袋装0.83g",
		img: 'http://baihang.com.cn/Upload/image/2021090904LMFFG9.jpg',
		price: 18.00
	}, {
		id: 5,
		title: "矮地茶配方颗粒",
		spcc: "每袋装0.83g",
		img: 'http://baihang.com.cn/Upload/image/2021090904LMFFG9.jpg',
		price: 18.00
	}])
</script>

<style lang="scss">
	.home {
		overflow-x: hidden;
	}

	.header {
		background: $main-color;
		padding: 20rpx 20rpx 100rpx;

		&-search {
			border-radius: 10rpx;
			overflow: hidden;
			position: relative;
			z-index: 2;
		}

		&-circle {
			height: 500rpx;
			margin-top: -330rpx;
			background: $main-color;
			clip-path: ellipse(52% 50% at 52% 50%);
			transform: scale(1.2);
		}
	}

	.home-swbox {
		padding: 0 20rpx;
		position: relative;
		z-index: 3;
		margin-top: -240rpx;
	}

	.home-swiper {
		height: 440rpx;

		image {
			display: block;
			width: 100%;
			height: 100%;
			border-radius: 10rpx;
		}
	}

	.home-news {
		padding: 20rpx;

		.home-newbox {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 10rpx 20rpx;
			background: #f4f4f4;
			border-radius: 10rpx;

			.home-newtit {
				flex-shrink: 0;
				font-size: 28rpx;
				color: $c0;
				font-weight: bold;
			}

			.news-sw {
				height: 44rpx;
				width: 100%;

				text {
					display: block;
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
					line-height: 44rpx;
					font-size: 26rpx;
					color: $c6;
				}
			}

			.newicon {
				flex-shrink: 0;
			}
		}
	}

	.fast-nav {
		display: grid;
		grid-template-columns: repeat(4, 1fr);
		grid-gap: 30rpx 0;
		padding: 20rpx 0;
		margin-bottom: 20rpx;

		&-item {
			text-align: center;

			image {
				display: block;
				width: 117rpx;
				height: 117rpx;
				margin: auto;
			}

			text {
				display: block;
				white-space: nowrap;
				font-size: 30rpx;
				color: $c3;
				margin-top: 20rpx;
			}
		}
	}

	.jxtj {
		padding: 0 20rpx;
		margin-bottom: 10rpx;

		&-box {
			background: url('') no-repeat $main-color top center/100% auto;
			border-radius: 10rpx;
			overflow: hidden;
		}

		&-top {
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin-bottom: 10rpx;
		}

		&-tit {
			display: flex;
			align-items: center;
			padding: 20rpx 80rpx 20rpx 20rpx;
			position: relative;
			overflow: hidden;

			image {
				width: 42rpx;
				height: 42rpx;
				position: relative;
				z-index: 2;
			}

			text {
				font-size: 36rpx;
				color: $main-color;
				font-weight: bold;
				position: relative;
				z-index: 2;
				margin-left: 15rpx;
			}

			&::after {
				content: "";
				position: absolute;
				left: -30rpx;
				top: -30rpx;
				bottom: 0;
				right: 25rpx;
				background: #f2f2f2;
				border-radius: 0 20rpx 20rpx 0;
				transform: skewX(-30deg);
			}
		}

		&-more {
			font-size: 30rpx;
			color: $cf;
			padding-right: 50rpx;
		}

		&-sws {
			padding: 20rpx;
		}
	}

	.jxsw {
		height: 440rpx;
		// border-radius: 30rpx;
		// overflow: hidden;
	}

	.jxswbox {
		display: grid;
		grid-template-columns: repeat(2, 1fr);
		background: $cf;
		border-radius: 10rpx;
		overflow: hidden;

		.jxitem {
			&:first-child {
				position: relative;

				&::after {
					content: "";
					position: absolute;
					top: 0;
					right: 0;
					width: 1px;
					height: 100%;
					background: #e7e7e7;
				}
			}

			.jximgbox {
				border-bottom: 1px solid #e7e7e7;
			}

			.jxtip {
				position: absolute;
				left: 5%;
				top: 5%;
				z-index: 2;
			}

			.jxinfo {
				padding: 20rpx;
			}
		}
	}

	.home-list {
		padding: 20rpx;

		.home-pitem {
			display: flex;
			justify-content: space-between;
			margin-bottom: 20rpx;
			border: 1px solid #eaeaea;
			border-radius: 10rpx;
			overflow: hidden;

			&-l {
				width: 50%;
				border-right: 1px solid #eaeaea;
			}

			.jxinfo {
				width: 50%;
				display: flex;
				flex-direction: column;
				justify-content: space-between;

				&-t {
					padding: 20rpx;
					background: #f8f8f8;
					height: 100%;
				}

				&-b {
					display: flex;
					align-items: center;
					justify-content: space-between;
					flex-shrink: 0;
					padding: 10rpx 20rpx;
					border-top: 1px solid #eaeaea;

					&-l {
						font-size: 24rpx;
						color: $c9;
					}

					&-r {
						width: 32rpx;
						height: 32rpx;
						border-radius: 50%;
						background: #f2f2f2;
						font-size: 16rpx;
						text-align: center;
						line-height: 32rpx;
						color: #a3a3a3;
					}
				}
			}
		}
	}
</style>